package com.wz.project.rgvqueue.service.impl;

import com.wz.common.utils.text.Convert;
import com.wz.project.rgvqueue.domain.RgvDeviceExecutionQueue;
import com.wz.project.rgvqueue.mapper.RgvDeviceExecutionQueueFinishMapper;
import com.wz.project.rgvqueue.mapper.RgvDeviceExecutionQueueMapper;
import com.wz.project.rgvqueue.service.IRgvDeviceExecutionQueueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * RGV执行队列Service业务层处理
 * 
 * @author wld
 * @date 2023-04-06
 */
@Service
public class RgvDeviceExecutionQueueServiceImpl implements IRgvDeviceExecutionQueueService
{
    @Autowired
    private RgvDeviceExecutionQueueMapper rgvDeviceExecutionQueueMapper;

    @Autowired
    private RgvDeviceExecutionQueueFinishMapper rgvDeviceExecutionQueueFinishMapper;

    /**
     * 查询RGV执行队列列表
     * 
     * @param rgvDeviceExecutionQueue RGV执行队列
     * @return RGV执行队列
     */
    @Override
    public List<RgvDeviceExecutionQueue> selectRgvDeviceExecutionQueueList(RgvDeviceExecutionQueue rgvDeviceExecutionQueue) {
        if (rgvDeviceExecutionQueue.getJdbz() == 1) {
            return rgvDeviceExecutionQueueMapper.selectRgvDeviceExecutionQueueList(rgvDeviceExecutionQueue);
        }else{
            return rgvDeviceExecutionQueueFinishMapper.selectRgvDeviceExecutionQueueList(rgvDeviceExecutionQueue);

        }
    }


    /**
     * 删除堆垛机执行队列信息
     *
     * @param queue 堆垛机执行队列
     * @return 结果
     */
    @Override
    public int deleteTask(RgvDeviceExecutionQueue queue) {

        int sa = 0;

        RgvDeviceExecutionQueue rgvQueue = rgvDeviceExecutionQueueMapper.selectRgvDeviceExecutionQueueByRwh(queue.getTaskNo());
        if(rgvQueue == null){
            return sa;
        }else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            rgvQueue.setFinish_time(sdf.format(new Date()));
            rgvQueue.setXf("2");
            rgvDeviceExecutionQueueFinishMapper.insertRgvDeviceExecutionQueue(rgvQueue);
            sa = rgvDeviceExecutionQueueMapper.deleteRgvDeviceExecutionQueueByRwh(queue.getTaskNo());
            return sa;
        }
    }

    @Override
    public int reloadTask(RgvDeviceExecutionQueue queue) {
        RgvDeviceExecutionQueue rgvDeviceExecutionQueue = rgvDeviceExecutionQueueMapper.selectRgvDeviceExecutionQueueByRwh(queue.getTaskNo());
        if(rgvDeviceExecutionQueue !=null) {
            queue.setStatus((long) 0);
            return rgvDeviceExecutionQueueMapper.updateRgvDeviceExecutionQueue(queue);
        }else{
            return 0;
        }
    }
}
